import request from '../utils/request';

export default {
    // 创建心情记录
    createMoodRecord(moodData) {
        // 使用FormData方式提交，确保textContent字段正确传递
        const formData = {
            textContent: moodData.description,
            emotionTag: moodData.moodLevel ? String(moodData.moodLevel) : '',
            emotionIntensity: moodData.moodLevel || 5
        };
        
        // 如果有图片，添加图片URL
        if (moodData.images && moodData.images.length > 0) {
            formData.imageUrl = moodData.images[0];
        }
        
        // 如果有语音，添加语音URL
        if (moodData.voice) {
            formData.audioUrl = moodData.voice;
        }
        
        return request.post('/mood', formData, 'application/x-www-form-urlencoded');
    },

    // 获取心情记录列表
    getMoodRecords(params) {
        return request.get('/mood/history', params);
    },

    // 获取心情记录详情
    getMoodRecordDetail(id) {
        return request.get(`/mood/${id}`);
    },

    // 更新心情记录
    updateMoodRecord(id, moodData) {
        return request.put(`/mood/${id}`, moodData);
    },

    // 删除心情记录
    deleteMoodRecord(id) {
        return request.delete(`/mood/${id}`);
    },

    // 获取今日心情
    getTodayMood() {
        return request.get('/mood/today');
    },

    // 获取心情报告
    getMoodReport() {
        return request.get('/mood/week-report');
    },

    // 获取心情趋势
    getMoodTrend(params) {
        return request.get('/mood/trend', params);
    }
}; 